<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let arr = [
        { name: "John", age: 25 },
        { name: "Pete", age: 30 },
        { name: "Mary", age: 28 },
      ];
      function sortByAge(a = []) {
        // a.sort((a, b) => a.age - b.age);
        a.sort((a, b) => (a.name > b.name ? 1 : -1));
      }
      sortByAge(arr);
      console.log(arr);
    </script>
  </body>
</html>
